﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Platformer2
{
    class effect
    {
        public Level Level
        {
            get { return level; }
        }
        Level level;

        public Vector2 Position
        {
            get { return position; }
        }
        Vector2 position;

        private float waitTime;

        private const float MaxWaitTime = 0.5f;

        private const float MoveSpeed = 128.0f;

        private Animation runAnimation; 
        
        private AnimationEffect sprite;

        private Rectangle localBounds;

        private FaceDirection direction = FaceDirection.Left;

        public bool IsActive;

        public effect(Level level , Vector2 position , string spriteSet , bool isLoop)
        {
            this.IsActive = true;

            this.level = level;
            this.position = new Vector2(position.X , position.Y);

            LoadContent(spriteSet , isLoop);
        }

        public void LoadContent(string spriteSet , bool isLoop)
        {
            // Load animations.
            spriteSet = "Sprites/" + spriteSet;
            runAnimation = new Animation(Level.Content.Load<Texture2D>(spriteSet), 0.1f, isLoop);           

            sprite.PlayAnimation(runAnimation);

            // Calculate bounds within texture size.
            //int width = (int)(runAnimation.FrameWidth * 0.35);
            //int left = (runAnimation.FrameWidth - width) / 2;
            //int height = (int)(runAnimation.FrameWidth * 0.7);
            //int top = runAnimation.FrameHeight - height;
            localBounds = new Rectangle(0, 0, 0, 0);
        }

        public void Update(GameTime gameTime)
        {

        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            // Stop running when the game is paused or before turning around.
            if (IsActive == false)
            {
                return;
            }
            else
            {
                sprite.PlayAnimation(runAnimation);
            }

            // Draw facing the way the enemy is moving.
            SpriteEffects flip = direction > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
            sprite.Draw(gameTime, spriteBatch, Position, flip);

            IsActive = !sprite.bEffectEnd;
        }
    }
}
